package com.hzbank.juc.studyvolatile;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @description:
 * @author: libugu@cskaoyan.com
 * @date 2023/12/25 - 19:38
 */
@Slf4j
public class Volatile01 {
    static boolean run = true;
    public static void main(String[] args) throws InterruptedException {

        Thread t = new Thread(()->{
            while(run){
                // ....
            }
        });
        t.start();

        TimeUnit.SECONDS.sleep(1);
        run = false; // 线程t不会如预想的停下来

        String re = Boolean.toString(run);

        Thread.currentThread().interrupt();

        log.debug(re);
    }
}
